#pragma semicolon 1
//#pragma newdecls required
#include <sourcemod>
#include <sdktools>

#define PLUGIN_NAME                   "l4d2_charger_upper_jump"    //这里写插件名字
#define PLUGIN_AUTHOR                 "豆瓣酱な"                         //作者
#define PLUGIN_DESCRIPTION            "Charger 普通攻击击飞玩家"   //介绍
#define PLUGIN_VERSION                "1.0"
#define PLUGIN_URL                    "https://gitee.com/sweet-and-sour-bombs"  //网站

public Plugin myinfo =
{
    name        = PLUGIN_NAME,
    author      = PLUGIN_AUTHOR,
    description = PLUGIN_DESCRIPTION,
    version     = PLUGIN_VERSION,
    url         = PLUGIN_URL
}

new Handle:sm_charger_upper			= INVALID_HANDLE;
new Handle:sm_charger_upper_force	= INVALID_HANDLE;

public void OnPluginStart()
{

	sm_charger_upper 		= CreateConVar("sm_charger_upper","1", "是否开启牛的拳头能力(0=关 1=开.)", FCVAR_NOTIFY, true, 0.0, true, 1.0);
	sm_charger_upper_force 	= CreateConVar("sm_charger_upper_force","400.0", "牛拳头能把人打多高", FCVAR_NOTIFY);
	CreateConVar("l4d2_sm_upper_version", PLUGIN_VERSION, "插件版本", FCVAR_NOTIFY);
	AutoExecConfig(true, "l4d2_charger_upper_jump");	
	HookEvent("player_hurt", Event_PlayerHurt, EventHookMode_Pre);
}

public Action:Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "attacker"));
	new target = GetClientOfUserId(GetEventInt(event, "userid"));
	
	decl String:weapon[64];
	GetEventString(event, "weapon", weapon, sizeof(weapon));
	
	if(client <= 0 || client > GetMaxClients())
		return;
	if(!IsValidEntity(client) || !IsClientInGame(client))
		return;
	if(!IsValidEntity(target) || !IsClientInGame(target))
		return;


	/* Charger claw blows off victim */
	if(StrEqual(weapon, "charger_claw") && GetConVarInt(sm_charger_upper))
	{
		new Float:power = GetConVarFloat(sm_charger_upper_force);
		Smash(client, target, power, 1.2, 1.5);
	}

}

public Smash(client, target, Float:power, Float:powHor, Float:powVec)
{
	decl Float:HeadingVector[3], Float:AimVector[3];
	GetClientEyeAngles(client, HeadingVector);
	
	AimVector[0] = FloatMul(Cosine(DegToRad(HeadingVector[1])) ,power * powHor);
	AimVector[1] = FloatMul(Sine(DegToRad(HeadingVector[1])) ,power * powHor);
	
	decl Float:current[3];
	GetEntPropVector(target, Prop_Data, "m_vecVelocity", current);
	
	decl Float:resulting[3];
	resulting[0] = FloatAdd(current[0], AimVector[0]);	
	resulting[1] = FloatAdd(current[1], AimVector[1]);
	resulting[2] = power * powVec;
	
	TeleportEntity(target, NULL_VECTOR, NULL_VECTOR, resulting);
}



























